<template>
	<el-header>
		<el-input v-model="search.keyword" placeholder="标题 / 摘要" clearable></el-input>
		<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
	</el-header>
	<el-main class="nopadding infinite-list" v-infinite-scroll="load" style="overflow:auto;height: 100%">
		<el-empty description="暂无记录" :image-size="100" v-if="recordList.length==0"></el-empty>
		<el-card v-for="item in recordList" class="infinite-list-item" :key="item.newsId" style="cursor: pointer;position: relative;" @click="showRecordList(item)">
			<template v-slot:header>
				<div v-if="item.readStatus=='false'" style="position: absolute;"><sc-icon-new/></div>
				<div style="text-overflow: ellipsis;overflow: hidden;white-space: nowrap;" :title="item.title">
					【{{item.voteTypeName}}】{{ item.title }}
				</div>
			</template>
			<sc-water-mark ref="wm" :text="waterMarkContent" :subtext="waterMarkSubtext" :showWater="waterMark=='1'">
			<div style="text-overflow: ellipsis;overflow: hidden;white-space: nowrap;" :title="item.subheading">
				{{ item.subheading }}
			</div>
			<div style="margin-top:10px;display: flex">
				<div style="display: contents;">
					<el-button type="primary" size="small" v-if="item.statusFlag===0&&item.vStatus==='1'">进行中</el-button>
					<el-button type="info" size="small" v-else>已结束</el-button>
				</div>
				<div style="display: inline-block;padding-top:5px;width: 100%">
					<span style="float: right;margin-left: 20px">
						<el-icon><el-icon-clock/></el-icon>{{ item.beginTime }}~{{ item.endTime }}
					</span>
				</div>
			</div>
			</sc-water-mark>
		</el-card>
	</el-main>
	<voteResult v-if="dialog.resultSave" ref="resultDialog" @closed="dialog.resultSave=false"></voteResult>
	<votedialog  v-if="dialog.detailsSave" ref="voteDialog" @success="handleSaveSuccess" @closed="dialog.detailsSave=false"></votedialog>
</template>

<script>
import Votedialog from "@/views/info/vote/votedialog";
import voteResult from '@/views/info/vote/result/index'
export default {
	components: {
		voteResult,
		Votedialog
	},
	data() {
		return {
			dialog: {
				resultSave:false,
				voteDialog:false,
			},
			loadFlag:true,
			loadStatus:true,
			recordList: [],
			search: {
				page: 0,
				keyword: ""
			},
			waterMarkContent:'',
			waterMarkSubtext:'',
			waterMark:'0',
		}
	},
	computed: {},
	mounted() {
		this.waterMark = this.$TOOL.data.get("WATER_MARK");
		this.waterMarkContent = this.$TOOL.data.get("WATER_MARK_CONTENT");
		this.waterMarkSubtext = this.$TOOL.data.get("WATER_MARK_SUBTEXT");
	},
	methods: {
		async upsearch() {
			this.recordList = [];
			this.search.page = 0;
			this.loadFlag = true;
			this.load();
		},
		load() {
			if(this.loadFlag&&this.loadStatus) {
				this.loadStatus = false;
				this.getMyVoteListForApp();
			}
		},
		async getMyVoteListForApp() {
			let res = await this.$API.info.vote.getMyVoteListForApp.get(this.search);
			if (res.code == 200) {
				this.recordList = this.recordList.concat(res.data);
				this.search.page = this.search.page + 10;
				this.loadStatus = true;
				if(res.data.length<10)
				{
					this.loadFlag = false
				}
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		showRecordList(item){
			if(item.statusFlag===0&&item.vStatus==='1')
			{
				this.dialog.detailsSave = true
				this.$nextTick(() => {
					this.$refs.voteDialog.open().setData(item)
				})
			}else
			{
				this.dialog.resultSave = true
				this.$nextTick(() => {
					this.$refs.resultDialog.open().setData(item)
				})
			}
		},
		//本地更新数据
		handleSaveSuccess() {
			location.reload();
		}
	}
}
</script>
